//
//  CYYNetWorkManager+takePartyInAParty.m
//  LetsPartyBmob
//
//  Created by rimi on 15/9/9.
//  Copyright (c) 2015年 柴阳阳. All rights reserved.
//

#import "CYYNetWorkManager+takePartyInAParty.h"

@implementation CYYNetWorkManager (takePartyInAParty)
//参加某个活动 （删除关注 + 参加活动）
//此操作在活动详情界面操作
/*
 partyObjectId : 上一个界面推送 过程中 传值过来的。。
 */
+ (void)takePartyInAPartyWithPartyObjectId:(NSString *)partyObjectId
                                    sucess:(Sucess)sucess
                                      fail:(Fail)fail{
    [CYYNetWorkManager deleteObservePartyWithObjectId:partyObjectId sucess:^(NSString *sucessString) {
        //取到改活动
        BmobObject *bmobObject = [BmobObject objectWithoutDatatWithClassName:@"Parties" objectId:partyObjectId];
        
        //取消关注 (不需要判断 是否有该对像存在)
        [CYYNetWorkManager deleteObservePartyWithObjectId:partyObjectId sucess:^(NSString *sucessString) {
            //新建relation对象
            BmobRelation *relation = [[BmobRelation alloc] init];
            [relation addObject:[BmobObject objectWithoutDatatWithClassName:@"_User" objectId:[CYYNetWorkManager currentUserGet].objectId]];
            
            [bmobObject addRelation:relation forKey:@"partyParticipators"];
            //把活动参加者 放到活动所有人当中
            [bmobObject addRelation:relation forKey:@"partyAllPeople"];
            
            [bmobObject updateInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
                if (isSuccessful) {
                    sucess(@"参加成功");
                }else{
                    fail(error);
                }
            }];
        } fail:^(NSError *error) {
            fail(error);
        }];
    } fail:^(NSError *error) {
        
    }];
}
@end
